<template>
  <div class="login">
    <div class="login-1">
      <el-form
        :model="form"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input type="username" v-model="form.username" autocomplete="off">
            <!-- <i class="el-icon-user-solid"></i> -->
          </el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="form.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item class="rigth">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { login } from '../api/user'
export default {
  name: 'LoginA',
  data () {



    return {
      form: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, massage: '用户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, massage: '密码不能为空', trigger: 'blur' },
        ],

      }

    }
  },
  created () {
  },
  computed: {
  },
  methods: {
    submitForm (form) {
      this.$refs[form].validate(async (valid) => {
        if (valid) {
          // alert('submit!');
          // console.log(valid);
          // const res = await login(formName)
          // console.log(res);
          await this.$store.dispatch('user/loginAction', this.form)
          this.$router.push('/welcome')
        } else {
          return false;
        }
      });
    },
    resetForm (form) {
      this.$refs[form].resetFields();
    }
  }
}

</script>
<style lang='less'  scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-color: #2b4b6b;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-1 {
    width: 50%;
    height: 50%;
    padding-top: 50px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
.rigth {
}
</style>
